diagnostics_channel: return original thenable#62407
Conversation
fc213c4 to
3eb07ea
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62407 +/- ##
==========================================
- Coverage 89.71% 89.68% -0.03%
==========================================
Files 692 692
Lines 213986 214005 +19
Branches 41055 41053 -2
==========================================
- Hits 191969 191940 -29
- Misses 14089 14140 +51
+ Partials 7928 7925 -3
🚀 New features to boost your workflow:
|
Renegade334
left a comment
There was a problem hiding this comment.
Does this change have a specific case in mind? The A+ standard mandates .then() to return another "promise" instance (either the same object or a new object at the implementation's discretion), so any custom features of a compliant thenable should also be present on the object returned by .then()?
|
No, that is not the case. A thenable can return any variety of promise, not necessarily another of itself. It's most common that a thenable returns native promises from its then/catch, so you lose access to whatever methods it had when following the chain. |
3eb07ea to
3d95103
Compare
3d95103 to
c5fcc50
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
81fd7b1 to
3299411
Compare
|
Nit: also having |
This makes tracePromise return the original thenable to allow custom thenable types to retain their methods rather than producing the chained result type.
3299411 to
b0e835c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
| return result.then(resolve, reject); | ||
| // isPromise() matches sub-classes, but we need to match only direct | ||
| // instances of the native Promise type to safely use PromisePrototypeThen. | ||
| if (isPromise(result) && result.constructor === Promise) { |
There was a problem hiding this comment.
So there's an edge case here... not convinced we necessarily need to deal with it but just acknowledging... it's exceedingly unlikely that someone would do this...
class MyP extends Promise {
constructor() { super(() => {});
}
const myP = new MyP();
myP.constructor = Promise;There was a problem hiding this comment.
might at least be worth adding a test for
This makes tracePromise return the original thenable to allow custom thenable types to retain their methods rather than producing the chained result type.
This branches the behaviour between native promises and thenables such that native promises retain the correct unhandledRejection behaviour while thenables produce the correct original return value and so retain methods present on that type.
I think that because native promises are consistently shaped it doesn't actually matter that it remains chained rather than branched.
cc @nodejs/diagnostics